package midterm.demo2;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test1 {
    public static void main(String[] args) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        List<User> users = new ArrayList<>();
        String userStrs = "10001:张三:男:1990-01-01#10002:李四:女:1989-01-09#10003:王五:男:1999-09-09" +
                "#10004:刘备:男:1899-01-01#10005:孙悟空:男:1900-01-01#10006:张三:女:1999-01-01" +
                "#10007:刘备:女:1999-01-01#10008:张三:女:2003-07-01#10009:猪八戒:男:1900-01-01";
        String regex = "\\d{5}:.{2,3}:.:\\d{4}-\\d{2}-\\d{2}";
        Pattern pattern  = Pattern.compile(regex);

        Matcher matcher = pattern.matcher(userStrs);

        while(matcher.find()){
           String s = matcher.group();
           String[] str = s.split(":");
           long id = Long.parseLong(str[0]);
           String name = str[1];
           String gender = str[2];
           LocalDate birthday = LocalDate.parse(str[3]);
           User user = new User(id, name, gender, birthday);
           users.add(user);
        }

        System.out.println(users);
    }

}
